$(function () {
    var token = sessionStorage.getItem("token");
    var plan_id = sessionStorage.getItem("plan_id");
    var method = "Planlist|detail";
    var d = {};
    d.token = token;
    d.plan_id = plan_id;
    d.method = method;
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: d,
        dataType: "json",
        async: false,
        success: function (result) {
            if (result.status == "1") {
                var data = result.data.plan_data;
                $(".order-no").html(data.order_no);
                $(".section").html(data.section);
                $(".money").html(data.money);
                $(".need_money").html(data.need_money);
                $(".fee").html(data.fee);
                $(".money_pay").html(data.money_pay);
                $(".money-cost").html(data.money_cost);
                var data1 = result.data.plan_list;
                var sttr = "";
                for (var i in data1) {
                    sttr += '<div class="am-u-sm-12 wai"  style="background: #fff;padding: 5px 25px 5px 10px;border-bottom: 1px solid #B4B4B4;"><div class="am-u-sm-6" style="font-size: 13px;">' + data1[i].deal_time + '</div>';
                    sttr += '<div class="am-u-sm-6" style="font-size: 17px;text-align: right;">' + data1[i].money + '</div>';
                    sttr += '<div style="font-size: 13px;">还款：<span style="color: red;">' + data1[i].status_name + '</span></div></div>'
                    sttr += '<div class="am-u-sm-12">';
                    var data2 = data1[i].cost_data;
                    for (var j in data2) {
                        sttr += ' <div class="am-u-sm-12" style="background:#F2F3F8;padding:0 15px;line-height:25px;font-size:12px;color:#333;"><div class="am-u-sm-6"><span>' + data2[j].deal_time + '</span><p style="margin: 0;">消费：<span style="color: red;">' + data2[j].status_name + '</span></p></div>';
                        sttr += '<div class="am-u-sm-6" style="text-align: right;padding-top: 10px;font-size: 15px;">' + data2[j].money + '</div></div>';
                    }
                    sttr += '</div>';
                }
                $(".xq").html(sttr);
                $(".wai").click(function () {
                    $(this).next().toggle(function () {
                        $(this).hide();
                    }, function () {

                    })
                });
                console.log(data);
                if (data.status == 0) {
                    $(".delPlan_btn").show();
                    $(".delPlan_btn").on('click', function () {
                        var method = "plan|hide_plan";
                        var d = {};
                        d.token = token;
                        d.plan_id = plan_id;
                        d.method = method;
                        $.ajax({
                            type: "post",
                            url: "http://www.rice.com/app/api/h5_access",
                            data: d,
                            dataType: "json",
                            success: function (result) {
                                // console.log(result);
                                if (result.status == 1) {
                                    alert(result.message);
                                    window.location.href = "Repayment.html";
                                } else {
                                    alert(result.message);
                                }
                            }
                        })
                    })
                } else if (data.status != 1) {
                    $(".termzzPlan_btn").show();
                    $(".termzzPlan_btn").on("click", function () {
                        var method = "plan|colse_plan";
                        var d = {};
                        d.token = token;
                        d.plan_id = plan_id;
                        d.method = method;
                        $.ajax({
                            type: "post",
                            url: "http://www.rice.com/app/api/h5_access",
                            data: d,
                            dataType: "json",
                            success: function (result) {
                                // console.log(result);
                                if (result.status == 1) {
                                    alert(result.message);
                                    window.location.href = "Repayment.html";
                                } else {
                                    alert(result.message);
                                }
                            }
                        })
                    })
                }

            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })


})